#{extends 'mainStage.html' /}

#{set title:'Valider les candidatures'  /}

    <div class="post">
        <h2 class="post-title">
			#{if candidats.size() != 0}
            	Liste des candidatures en attente de validation
			
        </h2>
        <br>
			#{form @envoieValidation()}
			<table width="200" cellspacing='0' cellpadding='7' id="liste" class="display" summary="Liste des candidats" bgcolor="#E1EEF0">
				<thead>
					<tr>
						<th>Nom</th>
						<th>Pr&eacute;nom</th>
						<th>Grade</th>
						<th>Statut</th>
						<th>R&ocirc;le</th>
						<th>Intitul&eacute;</th>
						<th>Date</th>
						<th>CIS ou Service</th>
						<th>Candidature partielle</th>
					 	<th>Priorit&eacute; du CIS</th>
					 	<th>Priorit&eacute; du groupement</th> 
						<th>Validation</th>
						<th>Pr&eacute;cisions</th>
					</tr>
				</thead>
				<tbody>
    		    #{list items:candidats, as:'candid' }
		       	<tr >
		           	<td><a href="@{candidats.detailCandid(candid.id)}">${candid.agent.nom}</a></td>
   		           	<td>${candid.agent.prenom}</td>
   		           	<td>${candid.agent.grade}</td>
				   	<td>${candid.agent.statut}</td>
					<td>${candid.role}</td>
					<td>
	        	            	#{if candid.stage!=null}
	        	                	<a href="@{Stages.detailStage(candid.stage.id)}">${candid.getStage().intitule}</a>
	        	                #{/if}
	                            #{else}
	                            	${candid.intitule}
	                            #{/else}
        	            	</td>
        	        <td>
        	        #{if candid.getStage()!=null}
	                            #{if candid.stage.dateDeb == null}
	                                -
	        	                #{/if}
	                            #{else}
	        	                    ${candid.stage.dateDeb.format('dd MMMM yyyy', 'fr')}
	                            #{/else}
                            #{/if}
                             #{else}
                            	Stage non planifi&eacute;
                            #{/else}
                    </td>
                     <td>${candid.agent.cisService} </td>
				   	<td>
                    #{if candid.candidPartielle}
                    	oui
                    	#{list items:candid.examenUv, as:'uv'}
							${uv}
						#{/list}
                    #{/if}
                    #{else}
                    	non
                    #{/else}
                    </td>
				   	<td>				   		
				   		#{if candid.ordrePrioriteCis!=null}
				   			${candid.ordrePrioriteCis}
				   		#{/if}
				   		#{else}
				   			-
				   		#{/else}				   		
				   	</td>
				   	<td id="tdChange${candid.id}">
				   		<div style="display:none" id="listePriorite${candid.id}">
				   			<select id="priorite${candid.id}" name="priorite${candid.id}" onchange="savePriorite(${candid.id})" style="width:auto;">
				   				<option>-- Priorit&eacute; --</option>
				   			#{list priorites, as:'priorite'}
				   				<option value="${priorite.id}">${priorite.ordre}</option> 
				   			#{/list}
				   			</select>
				   		</div>
				   		#{if candid.ordrePrioriteGrpmt!=null}
				   			${candid.ordrePrioriteGrpmt}
				   		#{/if}
				   		#{else}
				   			-
				   		#{/else}
				   		<a href="#" onClick="afficherList(${candid.id})">Modifier</a>
				   	</td>
				   	<td>
				   			Oui :<input type="radio" name="${candid.id}" id="O${candid.id}" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false; testBox('${candid.id}')" value="oui"><br/>
				   	        Non :<input type="radio" name="${candid.id}" id="N${candid.id}" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false; testBox('${candid.id}')" value="non"><br/>
							LA :<input type="radio" name="${candid.id}" id="L${candid.id}" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false; testBox('${candid.id}')" value="listeAttente">
				   	</td>
				<td><input type="text" class="precisions" size=2 id="R${candid.id}" name="R${candid.id}" disabled style="width: 50px;"></td>
		       	</tr>  
		        #{/list}
		    </tbody>
			</table>
			<input type="submit" value="valider changement">
		#{/form}
		#{/if}
		#{else}
			Aucune candidature en attente de validation 
		#{/else}
    </div>
	<script TYPE="text/javascript">
	function testBox(id){
		if(document.getElementById("N"+id).checked){
			document.getElementById("R"+id).disabled=false;
		}
		else if(!(document.getElementById("N"+id).checked)){
			document.getElementById("R"+id).disabled=true;
			document.getElementById("R"+id).value="";
		}
	}
	
	function afficherList(id){
		document.getElementById("listePriorite"+id).style.display="block";								        				   			
	}
	
	function savePriorite(id){
		var val=document.getElementById("priorite"+id).options[document.getElementById("priorite"+id).selectedIndex].value;
		$('#tdChange'+id).load("/priorite/"+id+'&'+val)
	}
	</script>